<?php

namespace App\Admin\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use \App\Models\Address;

class AddressesController extends AdminController
{
    protected $title = '收货地址';
    
    protected function grid()
    {
        $grid = new Grid(new Address());
	    $grid->model()->orderByDesc('id');
	
	    if ($userId = request('user_id')) {
		    $grid->model()->where('user_id', $userId)->orderByDesc('id');
	    }

        $grid->column('id', __('Id'));
        $grid->column('user_id', __('User id'));
        $grid->column('id_code', __('Id code'));
        $grid->column('id_name', __('Id name'));
        $grid->column('contact_name', __('Contact name'));
        $grid->column('contact_phone', __('Contact phone'));
        $grid->column('province', __('Province'));
        $grid->column('city', __('City'));
        $grid->column('district', __('District'));
        $grid->column('address', __('Address'));
        $grid->column('is_default', __('Is default'));
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));
	
	    $grid->quickSearch('user_id');
	
	    $grid->disableRowSelector();
	    $grid->disableCreateButton();
	    $grid->disableExport();
	    $grid->disableActions();

        return $grid;
    }
    
    protected function detail($id)
    {
        $show = new Show(Address::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('user_id', __('User id'));
        $show->field('contact_name', __('Contact name'));
        $show->field('contact_phone', __('Contact phone'));
        $show->field('province', __('Province'));
        $show->field('city', __('City'));
        $show->field('district', __('District'));
        $show->field('address', __('Address'));
        $show->field('is_default', __('Is default'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }
}
